/*
Valid Number Total Accepted: 30715 Total Submissions: 268253 My Submissions Question Solution
Validate if a given string is numeric.

Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.

Update (2015-02-10):
The signature of the C++ function had been updated. If you still see your function signature accepts a const char * argument, please click the reload button  to reset your
*/
#include <iostream>
#include "print.h"
#include <vector>
#include <algorithm>

using namespace std;


/***/
//Definition for an interval.
struct Interval {
	int start;
	int end;
	Interval() : start(0), end(0) {}
	Interval(int s, int e) : start(s), end(e) {}
};

class Solution {
public:
	bool isDigit(char c)
	{
		if (c-'0'>=0 && c-'0' <= 9 )
		{
			return true;
		}
		else
		{
			return false;
		}

	}

	bool isNumber(string s) {
		if (s.size() == 0)
		{
			return false;
		}
		int index = 0;
		while (s[index] == ' ')
		{
			++index;
		}
		while (s[index] == '+' || s[index] == '-')
		{
			++index;
		}
		
		bool exp = false, space = false, point = false;
		bool number = false;

		while (index != s.size())
		{
			if (isDigit(s[index]))
			{
				if (space) return false;
				else
				{
					number = true;
				}
			}
			else if (s[index] == '.')
			{
				if (!point && !space && !exp)
				{
					point = true;
				}
				else
				{
					return false;
				}
			}
			else if (s[index] == 'e')
			{
				if (!exp && number && !space)
				{
					exp = true;
					number = false;
					while (s[index+1] == '+' || s[index+1] == '-')
					{
						++index;
					}
				}
				else
				{
					return false;
				}
			}
			else if ( s[index] == ' ')
			{
				if (!space)
				{
					space = true;
				}
			}
			else
			{
				return false;
			}
			++index;
		}
		return number;
	}
};


struct Foo
{
	Foo(){ }
	Foo(int){ }
	void fun() { }

};

void test()
{
	int a = 1, b = 2, c = 3, d = 4;
	int e = (a < b ? a : c < d ? a : d);
		cout<<e<< endl;
}

int main()
{
	//int a[] = { 1, 1, 2 };
	vector<Interval> nums;
	Interval a2(1, 3), a1(6, 9), a3(2, 5), a4(15, 19);
	nums.push_back(a1);
	nums.push_back(a2);
	//nums.push_back(a3);
	//.push_back(a4);


	vector<Interval> res;
	Solution s;
	int n = 4;
	string str = "46.e3";
	bool flag = s.isNumber(str);
	//test();
	


	system("pause");
	return 0;
}